<?php

header("content-type:text/html;charset=utf-8");
require_once("./db.class.php");
$db=new Connection();	
$id=@$_REQUEST['id'];

$output=array('errcode'=>0,'msg'=>'ok');
if($id){

	//地区码
	$area_code=substr($id,0,6);
	//出生年月日
	$birth_code=substr($id,6,8);
	//顺序码
	$list_code=substr($id,14,3);
	//校验码
	$verify_code=substr($id,9,3);
	//加权因子
	$weight_arr=array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);
	//校验码对照表
	$verify_arr=array(1,0,'x',9,8,7,6,5,4,3,2,1);
	//乘积之和
	$sum=0;
	foreach($weight_arr as $key=>$val){
		$sum+=$val*$id[$key];
	}
	if($verify_arr[$sum%11]!=$id[17]){
		$output['errcode']=1;
		$output['msg']='id is invalid！';
	}else{
		$sql="select * from area_code where code='{$area_code}'";
		$query=$db->query($sql);
		$ret=$db->get_one($query);

		$data['area']=$ret['area']?$ret['area']:'未知地区';
		$data['list']=$list_code;
		$data['gender']=$list_code%2==0?'女':'男';
		$data['birthday']=date('Y年m月d日',strtotime($birth_code));
		$output['data']=$data;
	}

}else{
	$output['errcode']=1;
	$output['msg']='params id is required!';
}
// var_dump($output);
echo json_encode($output);





?>